home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pnl006.zip / BINARY.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-17  |  659b  |  26 lines

  1. Function binary(look : integer) :integer;{Find binary way}
  2. {Look is the variable you're looking for}
  3. var
  4.     temp,                                {The number}
  5.     b,mid,z,                             {Front and end}
  6.     f:integer;                           {For next loops}
  7. Begin
  8.  
  9.     b:=1;                                {Set variables}
  10.     z:=count;
  11.     temp:=-1;
  12.  
  13.     repeat
  14.  
  15.         mid:=(b+z) div 2;                  {Middle}
  16.  
  17.         if a[mid].id=look then temp:=a[mid].inv
  18.         else if a[mid].id<look then b:=mid+1
  19.         else if a[mid].id>look then z:=mid-1;
  20.  
  21.     until (temp>-1) or (b>z);
  22.  
  23.     binary:=temp;
  24.  
  25. End; 
  26.